require 'MVVM.Sources.View.Adaptor'

ClickAdaptor = class('ClickAdaptor', Adaptor)

function ClickAdaptor:ctor(gameObject, propertyName, binder, soundEffect)
    soundEffect = soundEffect or 'SoundEffect/2_close_btn'
    self.component = gameObject
    binder:RegisterEvent(function(viewModel, property)
        EventListener.AddClick(self.component, function()
            local onClick = property['OnClick']
            if onClick == nil then
                return
            end
            if #soundEffect > 0 then
                AudioManager.PlaySound(soundEffect)
            end
            onClick(self.component.name,gameObject)
        end)
    end, function()
        EventListener.Get(self.component.gameObject).onClick = nil
    end, propertyName)
end